/**
 * 可以运行，但是时间复杂度不符合题目要求
 *
 */

public class Test2 {


    public static void main(String[] args) {

        int[] nums = new int[]{1,4,5,6,7,8,9};
        Solution2 solution = new Solution2();
        solution.rotate(nums,2);

    }

}
class Solution2 {



    public void rotate(int[] nums, int k) {

        /*System.out.println("轮转前：");
        for (int i = 0; i < nums.length; i++) {

            System.out.println(nums[i]);

        }
*/


        int n = nums.length;
        for (int i = 0; i < k; i++) {



            //int tempLeft =0;
            //int tempRight = n - 1;
            //不用这样，倒着来，更清晰方便

            int num = nums[n - 1];
            for ( int j = n-1; j >0; j--) {//i < nums.length-1//注意在这里是减一还是减二
                //for ( i = nums.length-1; i >0; i--)

                //tempLeft = nums[i];
                //tempRight = nums[i+1];
                //nums[i+1] = tempLeft;

               //int temp = nums[i];
                nums[j] = nums[j-1];//不能在这里写成：j--或者--j
            }
            nums[0]=num;

        }

        for (int i = 0; i < n; i++) {

            System.out.println(nums[i]);

        }

    }

}